import { IFeidaoAiNodejsComponent } from '@dfeidao/atom-nodejs/interfaces';
import nodejs from '@dfeidao/atom-nodejs/msg/nodejs';
import render from '@dfeidao/atom-nodejs/render/render';
import p001 from './p001';
import p002 from './p002';
import p003 from './p003';
import p005 from './p005';
import p006 from './p006';
import p007 from './p007';
import p008 from './p008';
import p009 from './p009';
import p010 from './p010';
import p011 from './p011';
import p012 from './p012';
import p013 from './p013';
import p014 from './p014';
import p015 from './p015';
import p016 from './p016';
import p019 from './p019';
import p020 from './p020';
export default async function na001(fd: IFeidaoAiNodejsComponent) {
	// todo 页面渲染
	const equip_type_name = '';
	const equip_name = '';
	const fixed_assets_type = '';
	const page_no = 1;
	const res = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s001', {
		filter: {
			equip_type_name,
			equip_name,
			fixed_assets_type,
			page_no: 1
		}
	}) as { rs: Array<{}>, c: number };

	console.info(res);
	// const a = res[10].transfer_time;
	// alert(a)
	for (const v in res.rs) {
		const s = res.rs[v] as { _id: string, productid: string, equip_type_name: string, equip_type_no: string, equip_internal_no: string, equip_no: string, equip_name: string, equip_description: string, equipment_state: number, fixed_assets_type: string, fixed_assets_no: string, Former_equip_no: string, transfer_time: string, transfer_price: number, transfer_date: Date, manufacturer: string, manu_country: string, manu_element_no: string, manu_years: string, equip_model: string, series_no: string };
		const a = s.transfer_time;
		const b = s.manu_years;
		if (a) {
			const da = new Date(a);
			const year = da.getFullYear() + '年';
			const month = da.getMonth() + 1 + '月';
			const date = da.getDate() + '日';
			s.transfer_time = (year + month + date);
		}
		if (b) {
			const c = new Date(b);
			const y = c.getFullYear() + '年';
			const m = c.getMonth() + 1 + '月';
			const d = c.getDate() + '日';
			s.manu_years = (y + m + d);
		}
	}
	render(fd.data.node, res.rs, p003, 'p003');
	render(fd.data.node, { pageno: page_no, total: res.c }, p005, 'p005');



	// 设备设施类型下拉框数据
	const re = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s002', {

	});
	render(fd.data.node, re, p001, 'p001');


	// 固定资产类型下拉框
	const dszc = fd.data.node.querySelector('[data-zzs="gdzc"]').text;
	let value_title = dszc.substring(0, dszc.length - 1);
	const rs = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s003', {
		filter: {
			value_title
		}
	});

	const ssr = [];
	for (const c in rs) {
		const s = rs[c].value_no;
		ssr.push(s);
	}

	const sr = [];
	for (let i = 1; i < ssr.length; i++) {
		const value_no = ssr[i];
		const r = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s004', {
			filter: {
				value_no
			}
		});
		for (const n in r) {
			const k = r[n];
			sr.push(k);
		}
	}
	render(fd.data.node, sr, p002, 'p002');

	// 设备名称
	const uu = [{ equipment_kind_name: "" }];
	render(fd.data.node, uu, p006, 'p006');

	// 设备状态下拉框

	const sbzt = fd.data.node.querySelector('[data-zzs="zbzt"]').text;
	value_title = sbzt.substring(0, sbzt.length - 1);
	const ns = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s003', {
		filter: {
			value_title
		}
	});

	const ssn = [];
	for (const c in ns) {
		const s = ns[c].value_no;
		ssn.push(s);
	}

	const sn = [];
	for (let i = 1; i < ssn.length; i++) {
		const value_no = ssn[i];
		const r = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s004', {
			filter: {
				value_no
			}
		});
		for (const n in r) {
			const k = r[n];
			sn.push(k);
		}
	}
	render(fd.data.node, sn, p007, 'p007');

	// 所在区域下拉框

	const szpy = fd.data.node.querySelector('[data-zzs="szpy"]').text;
	value_title = szpy.substring(0, szpy.length - 1);
	const rrs = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s003', {
		filter: {
			value_title
		}
	});
	const nsn = [];
	for (const c in rrs) {
		const s = rrs[c].value_no;
		nsn.push(s);
	}
	const sns = [];
	for (let i = 1; i < nsn.length; i++) {
		const value_no = nsn[i];
		const r = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s004', {
			filter: {
				value_no
			}
		});
		for (const n in r) {
			const k = r[n];
			sns.push(k);
		}
	}
	render(fd.data.node, sns, p008, 'p008');

	// 安全等级标识

	const aqdj = fd.data.node.querySelector('[data-zzs="aqdj"]').structuredText;
	value_title = aqdj.substring(1, aqdj.length - 1);
	const qq = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s003', {
		filter: {
			value_title
		}
	});
	const ww = [];
	for (const c in qq) {
		const s = qq[c].value_no;
		ww.push(s);
	}
	const ee = [];
	for (let i = 1; i < ww.length; i++) {
		const value_no = ww[i];
		const r = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s004', {
			filter: {
				value_no
			}
		});
		for (const n in r) {
			const k = r[n];
			ee.push(k);
		}
	}
	render(fd.data.node, ee, p009, 'p009');

	// 所属公司下拉框
	const rr = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s006', {

	});
	render(fd.data.node, rr, p010, 'p010');

	// 计划工厂、维护工厂下拉框数据
	const ii = [{ factory_name: "" }];
	render(fd.data.node, ii, p011, 'p011');
	const i = [{ factory_name: "" }];
	render(fd.data.node, i, p019, 'p019');

	// 负责人、计划员下拉框
	const tt = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s008', {

	});
	render(fd.data.node, tt, p012, 'p012');

	// 保修负责部门下拉框

	const yy = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s009', {

	});
	render(fd.data.node, yy, p013, 'p013');

	// 保修负责人下拉框
	const oo = [{ staff_name: "" }];
	render(fd.data.node, oo, p014, 'p014');

	// 计划人员组
	const pp = await nodejs(fd.data.actionid, fd.data.sessionid, 'device-management/zj-000001/s011', {

	});
	render(fd.data.node, pp, p015, 'p015');

	// 计划员
	const aa = [{ staff_name: "" }];
	render(fd.data.node, aa, p016, 'p016');
	// 计划员下拉框
	const dd = [{ staff_name: "", staff_no: "" }];

	// render(fd.data.node, dd, p020, 'p020');
}
